<template>
	<view>
		<!--分享海报-->
		<goods-poster ref="poster" :poster='posterUrl' :category='category'></goods-poster>
	</view>
</template>

<script>
	import config from '@/config.js';
	import GoodsPoster from '@/subMyPage/components/Goods/GoodsPoster.vue'
	export default {
		components: {
			GoodsPoster
		},
		data() {
			return {
				configData: "",
				src: '',
				active: 1,
				operate: '',
				isWebview: true,
				posterUrl: '',
				category: ""
			};
		},
		onLoad(options) {
			console.log("onLoad")
			this.posterUrl = options.imageUrl;
			// #ifdef MP-WEIXIN
			//设置下方的Menus菜单，才能够让发送给朋友与分享到朋友圈两个按钮可以点击
			uni.showShareMenu({
				withShareTicket: true,
				menus: ["shareAppMessage", "shareTimeline"]
			})
			this.category = options.category
			// #endif
		},
		onShow() {
			console.log("onShow")
			this.configData = config.new_applet_info;
			setTimeout(() => {
				const value = uni.getStorageSync('imageUrl');
				if (value) {
					this.posterUrl = value;
				}
				this.$refs.poster.show();
			}, 1000)
		},
		// 设置分享方法
		onShareAppMessage(res) {
			let _this = this;
			if (res.from === 'button') { // 来自页面内分享按钮
				console.log(res.target)
			}
			return {
				title: '【甄标网】一手标源直卖平台',
				path: 'pages/index/index',
				imageUrl: 'https://i.danews.cc/xcx/share/index_share.jpg',

			}

		},

		methods: {
			saveImg(img) {
				var _this = this;
				let timestamp = Date.now();
				uni.showLoading({
					title: '正在下载中...'
				});
				wx.getFileSystemManager().writeFile({
					filePath: wx.env.USER_DATA_PATH + '/' + timestamp + '.png', //这里先把文件写到临时目录里. 
					data: img.slice(22), //注意这里
					encoding: 'base64',
					success: res => {
						wx.saveImageToPhotosAlbum({
							filePath: wx.env.USER_DATA_PATH + '/' + timestamp +
								'.png', //这是把临时文件 保存到 相册, 收工
							success: res => {
								uni.hideLoading();
								setTimeout(function() {
									uni.showToast({
										title: '下载成功，请到相册查看',
										duration: 2000,
										icon: 'none'
									});
								}, 1000) //延迟时间
							},
							fail: error => {
								console.log(error)
								wx.showToast({
									title: '下载失败'
								})
							}
						})
					},
					fail: error => {
						console.log(error)
						wx.showToast({
							title: '服务正忙'
						})
					}
				})
			}



		}
	}
</script>

<style lang="scss">

</style>